/*
 * Author: junz
 */

import { defHttp } from '/@/utils/http/axios';
import { Lesson, LessonListGetResultModel } from '/@/model/resource/lessonModel';
import { ErrorMessageMode } from '/#/axios';

enum Api {
  GET_LESSON_ENTITY_PAGE_LIST = '/continuingEducationCourse/lesson/page',
  GET_LESSON_ENTITY_LIST = '/continuingEducationCourse/lesson/list',
  GET_LESSON_ENTITY_BY_ID = '/continuingEducationCourse/lesson/',
  LESSON_ENTITY_UPDATE = '/continuingEducationCourse/lesson/updateById',
  LESSON_ENTITY_SAVE = '/continuingEducationCourse/lesson/save',
  LESSON_ENTITY_DEL = '/continuingEducationCourse/lesson/logicalRemoveById/',
  LESSON_BATCH_SAVE = '/continuingEducationCourse/lesson/batchSaveLessons',

  ALI_VOD_GET_CATEGORY_LIST = '/externalAli/aliVodCategory/getCategories/',
  ALI_VOD_GET_VIDEO_LIST = '/externalAli/aliVideo/getVideoList',
  ALI_VOD_GET_VIDEO_INFO = '/externalAli/aliVideo/getVideoInfo',
}

/**
 * @description: Get sample list value
 */

export const getLessonListApi = (params: {}) =>
  defHttp.get<Array<Lesson>>(
    { url: Api.GET_LESSON_ENTITY_LIST, params },
    { errorMessageMode: 'message' },
  );


export const getLessonPageApi = (params: {}) =>
  defHttp.get<LessonListGetResultModel>(
    { url: Api.GET_LESSON_ENTITY_PAGE_LIST, params },
    { errorMessageMode: 'message' },
  );

export const getLessonByIdApi = (id) =>
  defHttp.get<Lesson>({ url: Api.GET_LESSON_ENTITY_BY_ID + id }, { errorMessageMode: 'message' });

export function lessonUpdateApi(params: Lesson, mode: ErrorMessageMode = 'modal') {
  return defHttp.put<Lesson>(
    {
      url: Api.LESSON_ENTITY_UPDATE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export const lessonDelByIdApi = (id) =>
  defHttp.delete<Lesson>({ url: Api.LESSON_ENTITY_DEL + id }, { errorMessageMode: 'message' });

export function lessonSaveApi(params: Lesson, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<Lesson>(
    {
      url: Api.LESSON_ENTITY_SAVE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export const getAliVodCategoryListApi = (cateId: number) =>
  defHttp.get<LessonListGetResultModel>(
    { url: Api.ALI_VOD_GET_CATEGORY_LIST + cateId },
    { errorMessageMode: 'message' },
  );

export const getAliVideoListApi = (params: {}) =>
  defHttp.get<LessonListGetResultModel>(
    { url: Api.ALI_VOD_GET_VIDEO_LIST, params },
    { errorMessageMode: 'message' },
  );

export function lessonBatchSaveApi(params: Array<Lesson>, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<Array<Lesson>>(
    {
      url: Api.LESSON_BATCH_SAVE,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

export const getAliVideoInfoApi = (params: string) =>
  defHttp.get<LessonListGetResultModel>(
    { url: Api.ALI_VOD_GET_VIDEO_INFO+'/'+params  },
    { errorMessageMode: 'message' },
  );
